import { ConfigProvider, theme } from "antd";
import { SunOutlined, MoonOutlined } from "@ant-design/icons";
import type { ThemeConfig } from "types/theme";
import useThemeStore from "@/store/theme";

// 预设主题配置
const themeConfigs: ThemeConfig[] = [
  {
    algorithm: theme.defaultAlgorithm,
    name: "light",
    icon: <SunOutlined />,
    token: {
      colorPrimary: "#1677ff",
    },
  },
  {
    algorithm: theme.darkAlgorithm,
    name: "dark",
    icon: <MoonOutlined />,
    token: {
      colorPrimary: "#1677ff",
    },
  },
];

export default function ThemeProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  const { currentTheme } = useThemeStore();
  const currentThemeConfig = themeConfigs.find(
    (item) => item.name === currentTheme
  ) as ThemeConfig;
  console.log(currentThemeConfig,1111111);
  
  return (
    <ConfigProvider
      theme={{
        algorithm: currentThemeConfig.algorithm,
        token: currentThemeConfig.token,
      }}
    >
      {/* <div className="theme-provider__overlay"></div> */}
      {children}
    </ConfigProvider>
  );
}
